//
//  LQStatuses.swift
//  Weibo
//
//  Created by ios on 16/8/10.
//  Copyright © 2016年 ios. All rights reserved.
//

import UIKit

class LQStatuses: NSObject {
//微博创建时间
    var created_at: String?
//    微博ID
    var id: Int64 = 0
//    微博信息内容
    var text: String?
//    微博来源
    var source: String?
//  转发微博对象
    var retweeted_status: LQStatuses?
     //  匹配信息
    var pic_urls: [LQStatusPictureInfo]?
//  关注用户的模型
    var user: LQUser?
//    转发数
    var reposts_count: Int = 0
//    评论数
    var comments_count: Int = 0
//    表态数
    var attitudes_count: Int = 0
    init(dic: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dic)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
            guard let dic = value as? [String: AnyObject] else {
                
             return
                
            }
            user = LQUser(dic: dic)
        }else if key == "retweeted_status"{
            guard let dic = value as? [String: AnyObject] else {
                return
            }
            
            //  代码执行到此,字典没有问题
                retweeted_status = LQStatuses(dic: dic)
        
        }else if key == "pic_urls"{
            guard let dicArr = value as? [[String: AnyObject]] else {
                return
            }
            
            var tempArr = [LQStatusPictureInfo]()
            for dic in dicArr {
               let pictureInfo = LQStatusPictureInfo(dic: dic)
                tempArr.append(pictureInfo)
            }
            
            //设置模型数据
            pic_urls = tempArr
            
        }else{
            
        super.setValue(value, forKey: key)
            
        }
    }
    
    //  防止字段不匹配,导致崩溃
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
}
